package com.cn.star.java8;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.stream.Stream;

// 1程序实现目标：求一个整型数组中元素的平均值，并统计其中大于和小于此平均值的元素的个数
// 2手动输入一个存储整数的数组，要求输出数组里面的2个最大值
// 3有这样一类数字，他们顺着看和倒着看是相同的数，例如：121,656,2332等，这样的数字就称为：回文数字。编写一个函数，判断某数字是否是回文数字。
// 4手动输入一个字符串，仅限小写字母，统计并输出每个字符在字符串中出现的次数,并输出。提示(可以用Map)
public class Test08 {

	public static Double[] startMaxEndMin(Double[] arr) {
		Stream<Double> stream = Arrays.stream(arr);
		Double max = stream.max(Double::compareTo).get();
		Double min = stream.min(Double::compareTo).get();
		int i = Arrays.asList(arr).indexOf(max);
		arr[i] = arr[0];
		arr[0] = max;
		// 被交换了得重新转
		int j = Arrays.asList(arr).indexOf(min);
		arr[j] = arr[arr.length - 1];
		arr[arr.length - 1] = max;
		return arr;
	}

	public static String urlConn(String segId, String message) {
		String result = "";
		String url1 = "{\r\n" + 
				"	\"requestId\": \"201807201502331098799\",\r\n" + 
				"	\"securityToken\": \"65c1eac0-8f3f-4ab8-ac5b-cbb5e57c273b\",\r\n" + 
				"	\"modularCode\": \"lianxu_gw\",\r\n" + 
				"	\"interfaceType\": \"b0101\",\r\n" + 
				"	\"actionCode\": \"queryByIDCard\",\r\n" + 
				"	\"requestTime\": \"2018-07-20 15:02:33\",\r\n" + 
				"	\"verifyCode\": \"\",\r\n" + 
				"	\"requestParams\": {\r\n" + 
				"		\"idcard\": \"430124199710074010\"\r\n" + 
				"	}\r\n" + 
				"}";
		url1 = "https://ggwsfw.hnjky.org.cn/httpapi/services.ashx?data="+URLEncoder.encode(url1);
		try {
			System.out.println("url=" + url1);
			URL url = null;
			url = new URL(url1);
			HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
			urlcon.setRequestMethod("GET");
			urlcon.setRequestProperty("connection", "keep-alive");
			urlcon.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
			urlcon.connect(); // 获取连接
			InputStream is = urlcon.getInputStream();
			BufferedReader buffer = new BufferedReader(new InputStreamReader(is, "UTF-8"));
			StringBuffer bs = new StringBuffer();
			String l = null;
			while ((l = buffer.readLine()) != null) {
				bs.append(l);
			}
			System.out.println(bs.toString());
			result = bs.toString();
		} catch (IOException e) {
			e.printStackTrace();
			result = String.valueOf(e.getMessage());
		}
		return result;
	}

	public static void main(String[] args) {
		urlConn("","");
	}

}
